The network schematas for biological relevant boolean network models
In [1]:
%load_extautoreload%autoreload2%matplotlibinline
In [2]:
importos,sys,inspectcurrentdir=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))parentdir=os.path.dirname(currentdir)sys.path.insert(0,parentdir)#ABOVE added to use development version of canafrom__future__importdivisionimportosimportmathimportnumpyasnpimportpandasaspdpd.options.display.float_format='{:.2g}'.formatimportgraphvizimportcanafromcana.drawingimportdraw_canalizing_map_graphvizfromcana.drawingimportdraw_dynamics_canalization_map_graphvizimportmatplotlibasmplimportmatplotlib.stylempl.style.use('classic')frommatplotlib.textimportTextfrommatplotlib.patchesimportCircle,Rectangle,RegularPolygonfrommatplotlib.collectionsimportPatchCollectionimportrandomfromcopyimportcopympl.rc('font',**{'size':16})importmatplotlib.pyplotaspltfromcana.datasets.bioimportTHALIANA,DROSOPHILA,BUDDING_YEASTfromIPython.displayimportdisplay,Image,Latex,SVG,HTMLimportsubprocess#importjsonimportast#BELOW added for graphviz to work on windowsos.environ["PATH"]+=os.pathsep+"C:/Anaconda/pkgs/graphviz-2.38.0-4/Library/bin/"
#display only state variables, rather than each node state#create condensed set of nodes: {key original node, value supernode label}super_node_map={0:[0],1:[1],2:[1],3:[2],4:[3],5:[4],6:[5],7:[6],8:[7],9:[8],10:[9],11:[10],12:[11],13:[11],14:[12],15:[13],16:[14],17:[15],18:[16],19:[17],20:[17],21:[18],22:[18],23:[18],24:[19],25:[19],26:[20],27:[20],28:[21],29:[22],30:[22],31:[23],32:[24],33:[25],34:[26],35:[27],36:[28],37:[29],38:[30],39:[31],40:[32],41:[33],42:[34],43:[35],44:[36],45:[37],46:[38],47:[39],48:[40],49:[41],50:[42],51:[43],52:[44],53:[45],54:[45],55:[46],56:[47],57:[48],58:[48],59:[49],60:[49],61:[50],62:[50],63:[51],64:[52],65:[53],66:[53],67:[54],68:[54],69:[54],70:[55],71:[55],72:[55],73:[56],74:[56],75:[56],76:[56],77:[57],78:[57],79:[57]}#reverse_node_map = {node[0]:key for key,node in super_node_map.items()}ls=super_node_map.items()ls.reverse()#reverse list so that we keep the first name and overwrite the multi-state variantsatt={node[0]:{'label':nodes[key]}forkey,nodeinls}#create condensed set of edges, creates multigraphedges=[(super_node_map[edge[0]][0],super_node_map[edge[1]][0],edge[2])foredgeinNeg.edges(data=True)]#filter out multiple edges and average weightsall_edges={edge[0]:{}foredgeinedges}foredgeinedges:#calculate average in placeall_edges[edge[0]].setdefault(edge[1],{'weight':0,'number':0})all_edges[edge[0]][edge[1]]['number']+=1all_edges[edge[0]][edge[1]]['weight']+= \
(edge[2]['weight']-all_edges[edge[0]][edge[1]]['weight'])/all_edges[edge[0]][edge[1]]['number']averaged_edges=[(key1,key2,{'weight':all_edges[key1][key2]['weight']})forkey1inall_edgesforkey2inall_edges[key1]]#print Neg.edges(data=True)printlen(edges),len(averaged_edges)
229 124
In [10]:
#further condense to variables of interest, assumes ER is ESR1fig3_node_map={0:[0],1:[0],2:[0],3:[1],4:[2],5:[3],6:[4],7:[5],8:[6],9:[7],10:[8],11:[8],12:[8],13:[8],14:[9],15:[10],16:[11],17:[11],18:[12],19:[8],20:[8],21:[13],22:[13],23:[13],24:[14],25:[14],26:[15],27:[15],28:[16],29:[17],30:[17],31:[18],32:[19],33:[20],34:[21],35:[21],36:[22],37:[22],38:[23],39:[24],40:[25],41:[26],42:[27],43:[27],44:[28],45:[40],46:[28],47:[29],48:[30],49:[31],50:[32],51:[33],52:[34],53:[34],54:[34],55:[35],56:[36],57:[37],58:[37],59:[38],60:[38],61:[39],62:[39],63:[40],64:[41],65:[42],66:[42],67:[43],68:[43],69:[43],70:[44],71:[44],72:[44],73:[45],74:[45],75:[45],76:[45],77:[46],78:[46],79:[46]}ls=fig3_node_map.items()ls.reverse()#reverse list so that we keep the first name and overwrite the multi-state variantsatt={node[0]:{'label':nodes[key]}forkey,nodeinls}#manually fix labels to match figureatt[0]['label']='IGF1R'att[8]['label']='HER2/HER3'att[11]['label']='SGK1'att[21]['label']='p21/p27'att[22]['label']='cycE/CDK2'att[28]['label']='BIM'att[34]['label']='ESR1'att[40]['label']='BCL2'#create condensed set of edges, creates multigraphfig3_multi_edges,fig3_averaged_edges=[],[]fig3_multi_edges=[(fig3_node_map[edge[0]][0],fig3_node_map[edge[1]][0],edge[2])foredgeinNeg.edges(data=True)]#filter out multiple edges and average weightsfig3_all_edges={edge[0]:{}foredgeinfig3_multi_edges}foredgeinfig3_multi_edges:#calculate average in placefig3_all_edges[edge[0]].setdefault(edge[1],{'weight':0,'number':0})fig3_all_edges[edge[0]][edge[1]]['number']+=1fig3_all_edges[edge[0]][edge[1]]['weight']+= \
(edge[2]['weight']-fig3_all_edges[edge[0]][edge[1]]['weight'])/fig3_all_edges[edge[0]][edge[1]]['number']fig3_averaged_edges=[(key1,key2,{'weight':fig3_all_edges[key1][key2]['weight']}) \
forkey1infig3_all_edgesforkey2infig3_all_edges[key1]]printlen(fig3_multi_edges),len(fig3_averaged_edges)printatt
#alternative to show original edges, rather than effective weights (every edge weighted equally)foredgeinfig3_multi_edges:edge[2]['weight']=1foredgeinfig3_averaged_edges:edge[2]['weight']=1
In [11]:
#calculate positions for att, try 9x13 gridx,y=np.linspace(0,600,9,dtype=int),np.linspace(600,0,14,dtype=int)#enumerate all 47 nodesatt[0]['pos']='{:.2f},{:.2f}!'.format(x[2]/72,y[1]/72)#IGF1R #{'x':x[5],'y':y[0],'fillcolor':'#4f6fb0'}att[1]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[3]/72)#Fulvestrantatt[2]['pos']='{:.2f},{:.2f}!'.format(x[5]/72,y[3]/72)#Alpelisibatt[3]['pos']='{:.2f},{:.2f}!'.format(x[5]/72,y[4]/72)#Everolimusatt[4]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[2]/72)#Trametinibatt[5]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[4]/72)#Ipatasertibatt[6]['pos']='{:.2f},{:.2f}!'.format(x[7]/72,y[7]/72)#Palbociclibatt[7]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[0]/72)#Neratinibatt[8]['pos']='{:.2f},{:.2f}!'.format(x[1]/72,y[1]/72)#HER2/HER3 att[9]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[5]/72)#PDK1att[10]['pos']='{:.2f},{:.2f}!'.format(x[1]/72,y[5]/72)#mTORC2att[11]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[6]/72)#SGK1att[12]['pos']='{:.2f},{:.2f}!'.format(x[2]/72,y[5]/72)#PIMatt[13]['pos']='{:.2f},{:.2f}!'.format(x[1]/72,y[3]/72)#RASatt[14]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[3]/72)#MAPKatt[15]['pos']='{:.2f},{:.2f}!'.format(x[2]/72,y[3]/72)#PI3Katt[16]['pos']='{:.2f},{:.2f}!'.format(x[4]/72,y[2]/72)#PTEN att[17]['pos']='{:.2f},{:.2f}!'.format(x[4]/72,y[5]/72)#PIP3att[18]['pos']='{:.2f},{:.2f}!'.format(x[3]/72,y[6]/72)#PDK1_pmatt[19]['pos']='{:.2f},{:.2f}!'.format(x[5]/72,y[6]/72)#mTORC2_pmatt[20]['pos']='{:.2f},{:.2f}!'.format(x[4]/72,y[7]/72)#AKTatt[21]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[8]/72)#p21/p27att[22]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[9]/72)#cycE/CDK2att[23]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[6]/72)#KMT2Datt[24]['pos']='{:.2f},{:.2f}!'.format(x[4]/72,y[8]/72)#TSC att[25]['pos']='{:.2f},{:.2f}!'.format(x[3]/72,y[9]/72)#PRAS40att[26]['pos']='{:.2f},{:.2f}!'.format(x[4]/72,y[9]/72)#mTORC1att[27]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[9]/72)#FOXO3att[28]['pos']='{:.2f},{:.2f}!'.format(x[0]/72,y[11]/72)#BIMatt[29]['pos']='{:.2f},{:.2f}!'.format(x[1]/72,y[11]/72)#BADatt[30]['pos']='{:.2f},{:.2f}!'.format(x[3]/72,y[11]/72)#MCL1att[31]['pos']='{:.2f},{:.2f}!'.format(x[4]/72,y[10]/72)#EIF4Fatt[32]['pos']='{:.2f},{:.2f}!'.format(x[5]/72,y[10]/72)#S6K att[33]['pos']='{:.2f},{:.2f}!'.format(x[5]/72,y[11]/72)#Translationatt[34]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[1]/72)#ESR1att[35]['pos']='{:.2f},{:.2f}!'.format(x[7]/72,y[1]/72)#FOXA1att[36]['pos']='{:.2f},{:.2f}!'.format(x[8]/72,y[1]/72)#PBX1att[37]['pos']='{:.2f},{:.2f}!'.format(x[8]/72,y[4]/72)#ER_transcriptionatt[38]['pos']='{:.2f},{:.2f}!'.format(x[8]/72,y[6]/72)#MYCatt[39]['pos']='{:.2f},{:.2f}!'.format(x[8]/72,y[8]/72)#CyclinDatt[40]['pos']='{:.2f},{:.2f}!'.format(x[2]/72,y[11]/72)#BCL2 att[41]['pos']='{:.2f},{:.2f}!'.format(x[7]/72,y[8]/72)#CDK46att[42]['pos']='{:.2f},{:.2f}!'.format(x[8]/72,y[9]/72)#CycD_CDK46att[43]['pos']='{:.2f},{:.2f}!'.format(x[7]/72,y[10]/72)#pRbatt[44]['pos']='{:.2f},{:.2f}!'.format(x[7]/72,y[11]/72)#E2Fatt[45]['pos']='{:.2f},{:.2f}!'.format(x[6]/72,y[13]/72)#Proliferationatt[46]['pos']='{:.2f},{:.2f}!'.format(x[1]/72,y[13]/72)#Apoptosis#print att
In [12]:
#assign each node to a pathwayRTK_path=[0,8]PI3K_path=[15,16,17]MAPK_path=[13,14]AKT_path=[9,10,11,12,18,19,20,27]mTORC1_path=[24,25,26,31,32,33]ER_path=[23,34,35,36,37,38]apop_path=[28,29,30,40,46]prol_path=[21,22,39,41,42,43,44,45]drug_path=[1,2,3,4,5,6,7]fornodeinatt:ifnodeinRTK_path:att[node]['fillcolor']='#fb8072'elifnodeinPI3K_path:att[node]['fillcolor']='#80b1d3'elifnodeinMAPK_path:att[node]['fillcolor']='#ffffb3'elifnodeinAKT_path:att[node]['fillcolor']='#8dd3c7'elifnodeinmTORC1_path:att[node]['fillcolor']='#fdb462'elifnodeinER_path:att[node]['fillcolor']='#d9d9d9'elifnodeinapop_path:att[node]['fillcolor']='#b3de69'elifnodeinprol_path:att[node]['fillcolor']='#bebada'elifnodeindrug_path:att[node]['fillcolor']='#bc80bd'else:att[node]['fillcolor']='grey'
In [13]:
# Draw the Effective GraphE=graphviz.Digraph(name='Effective Graph',engine='neato')E.attr('graph',concentrate='false',simplify='false',splines='true')E.attr('node',shape='rectangle',fixedsize='true',width='.75',color='black',style='filled',penwidth='1',#fixedsize='true', width='.75'fontname='Helvetica',fontcolor='black',fontsize='10')E.attr('edge',arrowhead='normal',arrowsize='.5',color='#545454')#specify overrides to fixed size for the multigraph (for the averaged graph graphviz can calculate each width)att[8]['width']='1.0'#HER2/HER3att[19]['width']='1.0'#mTORC2_pmatt[37]['width']='1.2'#ER_transcriptionatt[42]['width']='1.0'#CycD_CDK46att[45]['width']='3.0'#proliferationatt[46]['width']='3.0'#apoptosis#for nid,d in Nsg.nodes(data=True):fornidinatt:natt=att[nid]E.node(name=str(nid),**natt)max_penwidth=2.5#for s,t,d in Neg.edges(data=True):fors,t,dinfig3_multi_edges:#use edges for multigraph or averaged_edges for regular graph (or fig3_multi_edges/fig3_averaged_edges)ifs==t:continue#include this line to get rid of self-loopsweight='%d'%(d['weight']*100)penwidth_scaled='%.2f'%((d['weight']/1)*max_penwidth)E.edge(str(s),str(t),weight=weight,penwidth=penwidth_scaled)print'Nodes: %d | Edges: %d'%(len(Neg.nodes()),len(Neg.edges()))# Displaydisplay(SVG(E.pipe(format='svg')),metadata={'isolated':True})# ExportE._format='svg'efile=u'%s/../experiments/2017 - BioModels/%s/graphs/EG'%(os.getcwd(),foldername)E.render(efile,cleanup=True)subprocess.call("inkscape -z '%s.svg' -d 300 -e '%s.png'"%(efile,efile),shell=True)
bound='upper'fori,ninenumerate(N.nodes):display(HTML('<h2>'+n.name+'</h2>'))print'Inputs:',n.inputsk=n.kk_r=n.input_redundancy(mode='node',bound=bound,norm=False)k_r_n=n.input_redundancy(mode='node',bound=bound,norm=True)k_e=n.effective_connectivity(mode='node',bound=bound,norm=False)k_s=n.input_symmetry(mode='node',bound=bound,norm=False)k_s_n=n.input_symmetry(mode='node',bound=bound,norm=True)dfS=pd.DataFrame([('k',k),('k_r',k_r),('k_e',k_e),('k_s',k_s),('k_r*',k_r_n),('k_s*',k_s_n)]).set_index(0).T#display(dfS)pi=n.schemata_look_up_table(type='pi',format='latex',ts_symbol_latex="\circ")ts=n.schemata_look_up_table(type='ts',format='latex',ts_symbol_latex="\circ")#display(Latex(pi))#display(Latex(ts))#multi_column_display([pi,ts],titles=['Prime Implicants','Two-Symbol Schemtas'],cols=4)# to make sure each SVG renders independently, add the "metadata={'isolated':True}CM=n.canalizing_map()gv=draw_canalizing_map_graphviz(CM)printCMdisplay(SVG(gv.pipe(format='svg')),metadata={'isolated':True})# Export to .SVGfilename=n.namefilename=filename.replace(',','_')filename=filename.replace('/','_')gv._format='svg'efile=u'%s/../experiments/2017 - BioModels/%s/CM/%s-%s'%(os.getcwd(),foldername,i,filename)gv.render(efile,cleanup=True)subprocess.call("inkscape -z -d 150 '%s.svg' -e '%s.png'"%(efile,efile),shell=True)#break
# Request the DCM to the NetworkDCM=N.dynamics_canalization_map(output=None)# Draws using the graphviz interface.D=draw_dynamics_canalization_map_graphviz(DCM,overlap='true')#display(D)# Export to .SVGD._format='svg'efile=u'%s/../experiments/2017 - BioModels/%s/DCM/DCM'%(os.getcwd(),foldername)D.render(efile,cleanup=True)subprocess.call("inkscape -z -d 150 '%s.svg' -e '%s.png'"%(efile,efile),shell=True)
Out[17]:
1
In [18]:
defplot_schemata(nid,n):# Init values from BooleanNodek=n.kifn.k>=1else1inputs=n.inputsifnotn.constantelse[n.name]pi0s,pi1s=n._prime_implicantsts0s,ts1s=n._two_symbols# Count number of PI and TSn_pi=sum(len(pis)forpisin[pi0s,pi1s])n_ts=sum(len(tss)fortssin[ts0s,ts1s])# Schemata Cell Width and spacingcwidth=60.cxspace=0cyspace=6border=1sepcxspace=21sepcyspace=15dpi=150.# Marginstop,right,bottom,left,hs=160,25,25,60,60# Axes Width & Heightax1width=((k*(cwidth+cxspace))+sepcxspace+(cwidth))ax1height=(n_pi*(cwidth+cyspace)+sepcyspace-cyspace)ax2width=((k*(cwidth+cxspace))+sepcxspace+(cwidth))ax2height=(n_ts*(cwidth+cyspace)+sepcyspace-cyspace)# Figure Width & Heightfwidth=(left+ax1width+hs+ax2width+right)fheight=(bottom+max(ax1height,ax2height)+top)# Percentages for Axes location_ax1w=((ax1width*100)/fwidth)/100_ax2w=((ax2width*100)/fwidth)/100_ax1h=((ax1height*100)/fheight)/100_ax2h=((ax2height*100)/fheight)/100_bottom=((bottom*100)/fheight)/100_left=((left*100)/fwidth)/100_hs=((hs*100)/fwidth)/100# Init Figurefig=plt.figure(figsize=(fwidth/dpi,fheight/dpi),dpi=dpi)ax1=fig.add_axes((_left,_bottom,_ax1w,_ax1h),aspect=1,label='PI')ax2=fig.add_axes((_left+_ax1w+_hs,_bottom,_ax2w,_ax1h),aspect=1,label='TS')### PI Plot ###yticks=[]patches=[]x,y=0.,0.#forout,pisinzip([1,0],[pi1s,pi0s]):forpiinpis:x=0.xticks=[]forinputinpi:ifinput=='0':facecolor='white'textcolor='black'elifinput=='1':facecolor='black'textcolor='white'elifinput=='2':facecolor='#cccccc'textcolor='black'text='%s'%(input)if(input!='2')else'#'ax1.add_artist(Text(x+cwidth/2,y+cwidth/10*4,text=text,color=textcolor,va='center',ha='center',fontsize=14,family='serif'))r=Rectangle((x,y),width=cwidth,height=cwidth,facecolor=facecolor,edgecolor='black')patches.append(r)xticks.append(x+cwidth/2)x+=cwidth+cxspacex+=sepcxspacer=Rectangle((x,y),width=cwidth,height=cwidth,facecolor='black'if(out==1)else'white',edgecolor='black')ax1.add_artist(Text(x-(sepcxspace/2)-(cxspace/2),y+cwidth/10*4,text=':',color='black',va='center',ha='center',fontsize=14,weight='bold',family='serif'))ax1.add_artist(Text(x+(cwidth/2),y+cwidth/10*4,text=out,color='white'if(out==1)else'black',va='center',ha='center',fontsize=14,family='serif'))patches.append(r)xticks.append(x+cwidth/2)yticks.append(y+cwidth/2)y+=cwidth+cyspacey+=sepcyspaceax1.add_collection(PatchCollection(patches,match_original=True))#ax1.set_yticks(yticks)ax1.set_yticklabels([r"$f^{'}_{%d}$"%(i+1)foriinrange(n_pi)[::-1]],fontsize=14)ax1.set_xticks(xticks)ax1.set_xticklabels(inputs+['%s'%(n.name)],rotation=90,fontsize=14)#ax1.xaxis.tick_top()# Remove Tickax1.tick_params(which='major',pad=7)forticinax1.xaxis.get_major_ticks():tic.tick1On=tic.tick2On=Falseforticinax1.yaxis.get_major_ticks():tic.tick1On=tic.tick2On=False# Remove Borderax1.spines['top'].set_visible(False)ax1.spines['right'].set_visible(False)ax1.spines['bottom'].set_visible(False)ax1.spines['left'].set_visible(False)# Limitsax1.set_xlim(-border,ax1width+border)ax1.set_ylim(-border,ax1height+border)#ax1.invert_yaxis() ## TS ##t=0x,y=0.,0.yticks=[]boxes,symbols=[],[]#tssymbols=[Circle((None,None),radius=5,facecolor='white',edgecolor='black'),RegularPolygon((None,None),numVertices=3,radius=5,orientation=0,facecolor='white',edgecolor='black'),]#forout,tssinzip([1,0],[ts1s,ts0s]):forts,pss,sssintss:x=0.xticks=[]fori,inputinenumerate(ts):ifinput=='0':facecolor='white'textcolor='black'elifinput=='1':facecolor='black'textcolor='white'elifinput=='2':facecolor='#cccccc'textcolor='black'iflen(pss):# TODO: If there are several symbols in the same input position, place them side-by-sideiinpss=[jforj,psinenumerate(pss)ifiinps]xpos=np.linspace(x,x+cwidth,len(iinpss)+2)forz,jinenumerate(iinpss,start=1):s=copy(tssymbols[j])s.xy=(xpos[z],y+cwidth*0.8)s.center=xpos[z],y+cwidth*0.8# A hack for circles onlys.set_edgecolor('#a6a6a6'if(input=='1')else'black')symbols.append(s)ax2.add_patch(s)text='%s'%(input)if(input!='2')else'#'ax2.add_artist(Text(x+cwidth/2,y+cwidth/10*4,text=text,color=textcolor,va='center',ha='center',fontsize=14,family='serif'))r=Rectangle((x,y),width=cwidth,height=cwidth,facecolor=facecolor,edgecolor='#4c4c4c',zorder=2)boxes.append(r)xticks.append(x+cwidth/2)x+=cwidth+cxspacex+=sepcxspacer=Rectangle((x,y),width=cwidth,height=cwidth,facecolor='black'if(out==1)else'white',edgecolor='#4c4c4c')ax2.add_artist(Text(x-(sepcxspace/2)-(cxspace/2),y+cwidth/2,text=':',color='black',va='center',ha='center',fontsize=14,weight='bold',family='serif'))ax2.add_artist(Text(x+(cwidth/2),y+cwidth/10*4,text=out,color='white'if(out==1)else'black',va='center',ha='center',fontsize=14,family='serif'))boxes.append(r)xticks.append(x+cwidth/2)yticks.append(y+cwidth/2)y+=cwidth+cyspacet+=1y+=sepcyspaceiflen(boxes):ax2.add_collection(PatchCollection(boxes,match_original=True))iflen(symbols):ax2.add_collection(PatchCollection(symbols,match_original=True))#ax2.set_yticks(yticks)ax2.set_yticklabels([r"$f^{''}_{%d}$"%(i+1)foriinrange(n_ts)[::-1]],fontsize=14)ax2.set_xticks(xticks)ax2.set_xticklabels(inputs+['%s'%(n.name)],rotation=90,fontsize=14)#ax2.xaxis.tick_top()# Remove Tickax2.tick_params(which='major',pad=7)forticinax2.xaxis.get_major_ticks():tic.tick1On=tic.tick2On=Falseforticinax2.yaxis.get_major_ticks():tic.tick1On=tic.tick2On=False# Remove Borderax2.spines['top'].set_visible(False)ax2.spines['right'].set_visible(False)ax2.spines['bottom'].set_visible(False)ax2.spines['left'].set_visible(False)# Limitsax2.set_xlim(-border,ax2width+border)ax2.set_ylim(-border,ax2height+border)# FileNamefilename=n.name.replace('/','_')filename=filename.replace(',','_')### SAVE to FILE ####plt.savefig('%s/../experiments/2017 - BioModels/%s/schematas/%s-%s' % (os.getcwd(), foldername, nid, filename), dpi=dpi)#plt.close()
C:\Users\tjparmer\AppData\Roaming\Python\Python27\site-packages\matplotlib\pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
max_open_warning, RuntimeWarning)